﻿#region Copyright information
// 
// Copyright © 2005-2013 Yongkee Cho. All rights reserved.
// 
// This code is a part of the Biological Object Library and governed under the terms of the
// GNU Lesser General  Public License (LGPL) version 2.1 which accompanies this distribution.
// For more information on the LGPL, please visit http://bol.codeplex.com/license.
// 
// - Filename: ValuedGenomicSegment.cs
// - Author: Yongkee Cho
// - Email: yongkeecho@gmail.com
// - Date Created: 2013-01-25 3:25 PM
// - Last Modified: 2013-01-25 3:59 PM
// 
#endregion
using System;
using System.Globalization;
using BOL.Models.Genome;

namespace BOL.Models.Features
{
    public class ValuedGenomicSegment<TValue> : GenomicSegment, IValued<TValue?>
        where TValue: struct
    {
        public TValue? Value { get; set; }

        public ValuedGenomicSegment(Chromosome chromosome, int from, int to, TValue value, Direction direction = Direction.Forward)
            : base(chromosome, from, to, direction)
        {
            Value = value;
        }

        public string ToBedGraphString()
        {
            return Value.HasValue ? String.Format("{0}\t{1}\t{2}\t{3}", Chromosome, From, To, Value) : String.Format("{0}\t{1}\t{2}", Chromosome, From, To);
        }

        public string ToWiggleString()
        {
            return Value.HasValue ? String.Format("{0}\t{1}", From, Value) : From.ToString(CultureInfo.InvariantCulture);
        }

        public override string ToString()
        {
            return Value.HasValue ? String.Format("{0}:{1}-{2}({3})", Chromosome, From, To, Value) : base.ToString();
        }
    }
}
